home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / examples / ptest.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  4KB  |  165 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: ptest.c,v 1.2 1997/07/09 13:25:15 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include "pvm3.h"
  35. #define GRP "group"
  36. #define DSIZE 10000
  37.  
  38. extern int pvmdebmask;
  39.  
  40. main(argc, argv)
  41. int argc;
  42. char **argv;
  43. {
  44.  
  45. int i;
  46. int j;
  47. int k;
  48. int l;
  49. int mytid;
  50. int mynod;
  51. int niter = 8;
  52. int ntask = 4;
  53. int pnod;
  54. int mydbmask = 0;
  55. int myiter = 1;
  56. double tstarray[DSIZE];
  57.  
  58.     mytid = pvm_mytid();
  59.  
  60.     if (argc > 1)
  61.         ntask = atoi(argv[1]);
  62.     else
  63.     {
  64.         printf("usage: ptest <nprocs> [debugmask] [niter] [sync/iteration]");
  65.         exit (-1);
  66.     }    
  67.  
  68.  
  69.     if (argc > 2)
  70.         mydbmask = atoi(argv[2]);
  71.  
  72.     if (argc > 3)
  73.         niter = atoi(argv[3]);
  74.  
  75.     if (argc > 4)
  76.         myiter = atoi(argv[4]);
  77.  
  78.     
  79.     printf("%x understands %d processes\n", mytid, ntask); 
  80.  
  81.     mynod = pvm_joingroup(GRP);
  82.  
  83.  
  84.     if (mynod == 0) 
  85.         pvmdebmask= mydbmask;
  86.  
  87.     pvm_freezegroup(GRP,ntask);
  88.  
  89.     pnod = pvm_gettid(GRP,0);
  90.  
  91.  
  92.  
  93.     for (i = 0; i < niter; i ++)
  94.     {
  95.          for (k = 0; k < DSIZE; k ++)
  96.             tstarray[k] = 2*k + mynod + (i*DSIZE);
  97.     
  98.         if (mynod == 0)
  99.         {
  100.             printf("Receiving data iter %d ...",i);
  101.     
  102.             if ( i > niter/2)
  103.                 printf(" (pvm_recv) ");
  104.             else
  105.                 printf(" (pvm_precv) ");
  106.  
  107.             printf("\n");
  108.             /* i_dump(1); */
  109.             for (j = 1; j < ntask; j ++)
  110.             {
  111.                 if ( i > niter/2)
  112.                 {
  113.                     pvm_recv(pvm_gettid(GRP,j),0);
  114.                     pvm_upkdouble(tstarray,DSIZE,1);
  115.                 }
  116.                 else
  117.                 {    
  118.                     pvm_precv(pvm_gettid(GRP,j), 0, tstarray, DSIZE, 
  119.                     PVM_DOUBLE, (int*)0, (int*)0, (int*)0);
  120.                 }
  121.                 for (k = 0; k < DSIZE; k++)
  122.                     if( tstarray[k] != (2*k + j + i*DSIZE) )
  123.                     {
  124.                         printf("Array match failed on iter %d, task %d index %d\n",    i, j, k);
  125.                         printf("Data should have been %f and was %f \n",
  126.                             (double)(2*k + j + i*DSIZE), tstarray[k]);
  127.                         printf("Next 10 values are :\n");
  128.                         l = k;
  129.                         for ( k = l; k < l + 10; k++)
  130.                         printf("%d should have been %f was  %f \n",k,
  131.                             (double)(2*k + j + i*DSIZE), tstarray[k]);
  132.                         exit(-1);
  133.                     }
  134.             }
  135.             printf("Data validated from all tasks! \n");
  136.             if ( (i % myiter) == 0)
  137.             {
  138.                 pvm_initsend(PvmDataDefault);
  139.                 pvm_pkint(&i,1,1);
  140.                 for (l =1; l < ntask; l++)
  141.                     pvm_send(pvm_gettid(GRP,l),10);
  142.             }
  143.         }
  144.         else
  145.         {
  146.             pvm_psend(pnod, 0, tstarray, DSIZE, PVM_DOUBLE);
  147.             if ( (i % myiter ) == 0)
  148.             {
  149.                 pvm_recv(pnod,10);
  150.                 pvm_upkint(&k,1,1);
  151.  
  152.                 if (k != i)
  153.                 {
  154.                     printf("%x received iteration count %d instead of %d \n",
  155.                     mytid, k, i);
  156.                     exit(-1);
  157.                 }
  158.             }
  159.         }
  160.     }
  161.     pvm_lvgroup(GRP);
  162.     pvm_exit();
  163. }
  164.  
  165.